package fcnet

const (
	HEAD_LEN   uint8 = 16
	CODEC_JSON uint8 = 1
)

type Head struct {
	Magic     uint16
	ID        uint32
	Typ       uint8
	Version   uint8
	CodecTyp  uint8
	HeadLen   uint8
	HeadExLen uint16
	DataLen   uint32
}

func (this Head) GetMagic() uint16 {
	return this.Magic
}
func (this Head) GetID() uint32 {
	return this.ID
}
func (this Head) GetTyp() uint8 {
	return this.Typ
}
func (this Head) GetVersion() uint8 {
	return this.Version
}
func (this Head) GetCodecTyp() uint8 {
	return this.CodecTyp
}
func (this Head) GetHeadLen() uint8 {
	return this.HeadLen
}
func (this Head) GetHeadExLen() uint16 {
	return this.HeadExLen
}
func (this Head) GetDataLen() uint32 {
	return this.DataLen
}

type Msg struct {
	Head
	HeadEx []byte
	Data   []byte
}

func NewMsg(id uint32, data []byte) *Msg {
	msg := &Msg{
		Head: Head{
			ID:       id,
			HeadLen:  HEAD_LEN,
			DataLen:  uint32(len(data)),
			Typ:      uint8(1),
			Version:  uint8(10),
			CodecTyp: CODEC_JSON,
		},
		Data: data,
	}
	return msg
}

func (this *Msg) GetHead() any {
	return this.Head
}

func (this *Msg) GetHeadEx() []byte {
	return this.HeadEx
}
func (this *Msg) SetHeadEx(ex []byte) {
	this.HeadEx = ex
}

func (this *Msg) GetHeadExLen() uint16 {
	return this.HeadExLen
}
func (this *Msg) SetHeadExLen(l uint16) {
	this.HeadExLen = l
}

func (this *Msg) GetDataLen() uint32 {
	return this.DataLen
}
func (this *Msg) SetDataLen(l uint32) {
	this.DataLen = l
}

func (this *Msg) GetMsgID() uint32 {
	return this.ID
}
func (this *Msg) SetMsgID(id uint32) {
	this.ID = id
}

func (this *Msg) GetData() []byte {
	return this.Data
}
func (this *Msg) SetData(data []byte) {
	this.Data = data
}
